package com.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 聊天消息实体类
 */
@TableName("chat_message")
public class ChatMessage implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 消息ID
     */
    @TableId(value = "id", type = IdType.UUID)
    private String id;

    /**
     * 发送者OpenID
     */
    @TableField("sender_openid")
    private String senderOpenid;

    /**
     * 接收者OpenID
     */
    @TableField("receiver_openid")
    private String receiverOpenid;

    /**
     * 消息内容
     */
    @TableField("content")
    private String content;

    /**
     * 消息类型：text, image, file, voice, video
     */
    @TableField("message_type")
    private String messageType;

    /**
     * 消息状态：sent, delivered, read, recalled
     */
    @TableField("status")
    private String status;

    /**
     * 发送时间
     */
    @TableField("send_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date sendTime;

    /**
     * 读取时间
     */
    @TableField("read_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date readTime;

    /**
     * 文件URL（用于图片、文件、语音、视频消息）
     */
    @TableField("file_url")
    private String fileUrl;

    /**
     * 文件大小（字节）
     */
    @TableField("file_size")
    private Long fileSize;

    /**
     * 文件名称
     */
    @TableField("file_name")
    private String fileName;

    /**
     * 消息扩展信息（JSON格式）
     */
    @TableField("extra_info")
    private String extraInfo;

    // 构造函数
    public ChatMessage() {
        this.sendTime = new Date();
        this.status = "sent";
        this.messageType = "text";
    }

    public ChatMessage(String senderOpenid, String receiverOpenid, String content) {
        this();
        this.senderOpenid = senderOpenid;
        this.receiverOpenid = receiverOpenid;
        this.content = content;
    }

    // Getter和Setter方法
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSenderOpenid() {
        return senderOpenid;
    }

    public void setSenderOpenid(String senderOpenid) {
        this.senderOpenid = senderOpenid;
    }

    public String getReceiverOpenid() {
        return receiverOpenid;
    }

    public void setReceiverOpenid(String receiverOpenid) {
        this.receiverOpenid = receiverOpenid;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getMessageType() {
        return messageType;
    }

    public void setMessageType(String messageType) {
        this.messageType = messageType;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getSendTime() {
        return sendTime;
    }

    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }

    public Date getReadTime() {
        return readTime;
    }

    public void setReadTime(Date readTime) {
        this.readTime = readTime;
    }

    public String getFileUrl() {
        return fileUrl;
    }

    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getExtraInfo() {
        return extraInfo;
    }

    public void setExtraInfo(String extraInfo) {
        this.extraInfo = extraInfo;
    }

    @Override
    public String toString() {
        return "ChatMessage{" +
                "id='" + id + '\'' +
                ", senderOpenid='" + senderOpenid + '\'' +
                ", receiverOpenid='" + receiverOpenid + '\'' +
                ", content='" + content + '\'' +
                ", messageType='" + messageType + '\'' +
                ", status='" + status + '\'' +
                ", sendTime=" + sendTime +
                ", readTime=" + readTime +
                ", fileUrl='" + fileUrl + '\'' +
                ", fileSize=" + fileSize +
                ", fileName='" + fileName + '\'' +
                ", extraInfo='" + extraInfo + '\'' +
                '}';
    }
}
